<template>
    <view>
        <form>
            
            <!-- <view class="cu-form-group margin-top">
                <view class="title">项目编号</view>
                <view>{{ dataInfo.projectno }}</view>
            </view>
            <view class="cu-form-group ">
                <view class="title">项目名称</view>
                <view>{{ dataInfo.projectname }}</view>
            </view> -->
            <xmInfo
      :projectno="dataInfo.projectno"
      :projectname="dataInfo.projectname"
    ></xmInfo>
			<view class="cu-form-group " style="margin-top: 10px;">
			    <view class="title">推送状态</view>
			    <js-select class="input-align" v-model="dataInfo.iswatersupply" :disabled="true" dict-type="zf_push_bz_status" placeholder=" "></js-select>
			</view>
			
			<view class="cu-form-group" style="min-height: 0;"></view>

            <view class="cu-bar bg-white">
                <view class="action"><text class="cuIcon-favorfill text-xs text-red"></text>推送报装附件</view>
            </view>
			<!-- <view class="cu-bar bg-white">
				<js-uploadfile v-model="dataInfo.dataMap" :biz-key="dataInfo.id" biz-type="ProjectPushBz_file"></js-uploadfile>
			</view> -->
           <!-- <file-upload :uploadOptions="uploadOptions" :imgList="imgList" @imgListChange="imgListChange"></file-upload> -->
           <view class="cu-form-group">
            <js-uploadfile
              v-if="uploadFile"
              v-model="dataInfo.dataMap"
              :biz-key="dataInfo.id"
              biz-type="ProjectPushBz_file"
              uploadType="image"
              uploadText="请上传文件"
              style="width: 100%"
			  :deletable="dataInfo.iswatersupply!=1" :customBtn="dataInfo.iswatersupply==1"
            ></js-uploadfile>
          </view>
		  
		  <view class="cu-form-group" style="min-height: 0;"></view>
		  <view class="cu-bar bg-white">
		      <view class="title action">推送异常信息</view>
		  </view>
		  <view class="cu-form-group">
			  {{dataInfo.errorcontent || ''}}
		    <!-- <textarea
		      v-model="dataInfo.errorcontent"
		  	placeholder-class="line"
		  	type="text"
		      placeholder="请输入推送异常信息"
		    ></textarea> -->
		  </view>

          <view style="height: 80px" ></view>
		  <!-- v-if="dataInfo.iswatersupply==0"  -->
          <view class="btn-group cu-bar foot" >
				<button class="cu-btn shadow-blur" @click="bzKhQty" v-if="viewflag">查看开户数</button>
                <button class="cu-btn bg-blue shadow-blur" v-if="dataInfo.iswatersupply!=1&&editflag" @click="save">推送报装</button>
          </view>
        </form>
		<u-picker mode="time" v-model="startTime" @confirm="startConfirm"></u-picker>
        
		<u-popup v-model="khshow" mode="center"  border-radius="14">
			<view style="padding: 50px 60px;text-align: center;">
				<view class="text-bold" style="font-size: 30px;margin-bottom: 10px;">开户信息</view>
				<view class="text-bold" style="font-size: 36px;">{{khdata.OpenedCount || '0'}} / {{khdata.TotalCount || '0'}}</view>
			</view>
			
		</u-popup>
    </view>
</template>
<script>
import xmInfo from "@/pages/zfgs/index/componetns/xmInfo.vue";
import {hasPermission} from '@/common/fire.js'
export default {
    components:{
        xmInfo
    },
    data(){
        return{
			khdata:{},
			khshow: false,
			startTime: false, //控制日期显示
            switchA: false,
            date: '2024-03-12',
            modalName: null,
            uploadOptions:{
				
			},
            imgList:[],
            imageUrl: ["http://192.168.1.49:8080/app/static/image/zfgs/zfgs1.jpg","http://192.168.1.49:8080/app/static/image/zfgs/zfgs2.jpg"],
            modalNameDetail: null,
            showAddDetail:false,
            dataInfo:{ },
            showButton : true,
            uploadFile:false,
            isSubmitting: false,
            viewflag : hasPermission('app:btn:view:tstbz'),
            editflag : hasPermission('app:btn:send:tstbz'),
        }
    },
    onLoad(params){
        this.uploadFile = true
		let item = JSON.parse(params.item);
		this.$u.api.zfgs.pmProjectinformationForm({id:item.id}).then(res=>{
			this.dataInfo = res.pmProjectinformation
			// this.dataInfo = {
			// 	iswatersupply:res.pmProjectinformation.iswatersupply,
			// 	projectno:res.pmProjectinformation.projectno,
			// 	projectname:res.pmProjectinformation.projectname,
			// 	isNewRecord:res.pmProjectinformation.isNewRecord,
			// 	id:res.pmProjectinformation.id,
			// }
			
		})
    },
    methods:{
		bzKhQty(){
			this.$u.api.zfgs.pmProjectinformationBzKhQty({id:this.dataInfo.id}).then(res=>{
			      // this.khshow = true
				if (res.result == "true") {
					this.khdata = res
					this.khshow = true
			    } else {
					uni.showModal({
						title: "提示",
						content: res.message,
						showCancel: false,
						success: (res) => {},
					});
			    }
			    
			})
		},
		save(){
            if (!this.dataInfo.dataMap || !this.dataInfo.dataMap.ProjectPushBz_file) {
                this.$u.toast("推送报装附件必传");
                return;
            }
            if (this.isSubmitting) {
                return;
            } else {
                this.isSubmitting = true;
                try {
                    this.$u.api.zfgs.pushBzSave(this.dataInfo).then(res=>{
                        if (res.result == "true") {
                            this.$u.toast(res.message);
                        setTimeout(() => {
                            uni.navigateBack({
                            delta: 1,
                            });
                        }, 500);
                        } else {
                        uni.showModal({
                            title: "提示",
                            content: res.message,
                            showCancel: false,
                            success: (res) => {},
                        });
                        }
                        
                    })
                } catch (error) {
                this.$u.toast(error.message);
                } finally {
                this.isSubmitting = false;
                }
            }
		},
		startConfirm(e) {
			this.dataInfo.endtime = e.year + "-" + e.month + "-" + e.day;
		},
        SwitchA(e) {
            // this.switchA = e.detail.value
        },
        DateChange(e) {
            this.date = e.detail.value
        },
        textareaAInput(e){
            this.dataInfo.dmark = e.detail.value
        },
        addDetail(){

            this.showAddDetail = true
            
            this.modalNameDetail = 'bottomModal'

            console.log(this.modalNameDetail)
        },
        modalNameDetailEmit(e){
            this.modalNameDetail = e
        },

        ViewImage(imageList,e) {
            uni.previewImage({
                urls: imageList,
                current: e.currentTarget.dataset.url
            });
        },
        DelImg(e) {
            uni.showModal({
                title: '',
                content: '确定要删除吗？',
                cancelText: '取消',
                confirmText: '确认',
                success: res => {
                    if (res.confirm) {
                        console.log(res.confirm,this.dataInfo.dImageList ,e,this.dataInfo.dImageList[e.currentTarget.dataset.index]);
                        // this.dataInfo.dImageListst.splice(e.currentTarget.dataset.index, 1)
                        // if (this.dataInfo.dImageListst) {
                        //     console.log(e.currentTarget.dataset.index,this.dataInfo.dImageListst,'e====')
                        //     this.dataInfo.dImageListst.splice(e.currentTarget.dataset.index, 1);
                        // }
                        // this.$set(this.dataInfo.dImageListst, e.currentTarget.dataset.index,1)
                        // this.dataInfo.dImageListst.splice(e.currentTarget.dataset.index, 1);
                        this.$delete(this.dataInfo.dImageListst, e.currentTarget.dataset.index);
                        
                        
                    }
                }
            })
        },
        ChooseImage() {
            uni.chooseImage({
                count: 4, //默认9
                sizeType: ["original", "compressed"], //可以指定是原图还是压缩图，默认二者都有
                sourceType: ["album"], //从相册选择
                success: (res) => {
                    if (this.dataInfo.finishImgList.length != 0) {
                        this.dataInfo.finishImgList = this.dataInfo.finishImgList.concat(res.tempFilePaths);
                    } else {
                        this.dataInfo.finishImgList = res.tempFilePaths;
                    }
                    
                    console.log(this.dataInfo,'this.dataInfo')
                    this.$u.toast("上传成功");
                }
            });
        },

    }
}
</script>
<style lang="scss" scoped>
	/deep/.u-input__input.data-v-460c1d26 {
	    text-align: right !important;
	}
.action{
    color: #303133;
}
.title{
    flex-shrink: 0;
}
.text-sl{
    font-size: 22px !important;
}
.cu-bar {
  min-height: 80px;
}
.cu-btn {
  font-size: 16px;
  height: 40px;
}
.foot{
    z-index: 997;
    background: #fff;
}
.green{
    color: green;
}
.input-align{
    text-align: right;
}
.text-xs {
  font-size: 18rpx !important;
}
::v-deep .u-input__input{
    text-align: right ;
}
</style>